<template>
  <div class="Login">
    <div class="b">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item prop="pass" class="a">
          <el-input
            type="userNum"
            placeholder="请输入账号"
            v-model="ruleForm.userNum"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item prop="checkPass" class="a">
          <el-input
            type="password"
            placeholder="请输入密码"
            v-model="ruleForm.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >提交</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { userLogin } from "../../apis/user";
export default {
  name: "Login",
  data() {
    return {
      ruleForm: {
        userNum: "",
        password: "",
      },
      rules: {},
    };
  },
  methods: {
    submitForm(formName) {
      console.log(formName);
      userLogin(this.ruleForm)
        .then((data) => {
          let _this = this;
          _this.$store.commit("setToken", data);
          this.$router.push("/user/index");
        })
        .catch();
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.Login {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.b {
  background-color: rgb(227, 246, 246);
  width: 600px;
  height: 500px;
  border-radius: 10px;
  padding-top: 10%;
}
.a {
  width: 400px;
  padding-left: 100px;
}
</style>
